//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<IEntityImplAttr.cpp>
///	@path	~/src/scene/
///	@date	2007/11/05
///	@desc	Entity with implementation of attribute management.

#include "config/config.h"

#include "scene/IAttribute.h"
#include "scene/IEntityImplAttr.h"

namespace xeres {

	IMPL_IOBJECT_INTERFACE( IEntityImplAttr );

	// ctor
	IEntityImplAttr::IEntityImplAttr( void )
	{
	}

	// dtor
	IEntityImplAttr::~IEntityImplAttr( void )
	{
	}

	// get attribute
	RefWeak<IAttribute> IEntityImplAttr::GetAttribute( int attributeID )
	{
		return ImplGetAttribute( attributeID );
	}

	// get attribute
	RefWeak<IAttribute> IEntityImplAttr::ImplGetAttribute( int attributeID )
	{
		AttributeMap::iterator it = m_attrMap.find( attributeID );
		if( it == m_attrMap.end() )
			return RefWeak<IAttribute>(NULL);
		return it->second;
	}

	// query attribute exists
	bool IEntityImplAttr::ImplExistAttribute( int attributeID )
	{
		AttributeMap::iterator it = m_attrMap.find( attributeID );
		return( it != m_attrMap.end() );
	}

	// set attribute
	bool IEntityImplAttr::ImplSetAttribute( int attributeID , RefWeak<IAttribute> attr )
	{
		AttributeMap::iterator it = m_attrMap.find( attributeID );
		if( it != m_attrMap.end() )
			return false;
		m_attrMap[ attributeID ] = attr;
		return true;
	}

	// replace attribute
	bool IEntityImplAttr::ImplReplaceAttribute( int attributeID , RefWeak<IAttribute> attr )
	{
		AttributeMap::iterator it = m_attrMap.find( attributeID );
		if( it == m_attrMap.end() )
			return false;
		it->second = attr;
		return true;
	}

} // namespace xeres
